﻿using EIP.HRP.Models.Entities;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.ComponentModel.DataAnnotations;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //生成GUID
            //var  sStr = "\\";
            //byte[] imgStr = new byte[10000];
            //var base64 = Convert.ToBase64String(imgStr);
            //for (int i = 0; i < 64; i++)
            //{
            //    Console.WriteLine($"{Guid.NewGuid()}");
            //}
            //Console.WriteLine(\\"Hello World!\\");
            //var date = new DateTime(2020,1,1);
            //Console.WriteLine(date.ToLongDateString());
            //Console.WriteLine(date.ToShortTimeString());
            //Console.WriteLine(date.ToString(\\"yyyy.MM.dd\\"));

            //            var str = {
            //    \\"groupOp\\":\\"OR\\",
            //    \\"rules\\":[
            //        {
            //            \\"field\\":\\"NativePlace\\",
            //            \\"op\\":\\"cn\\",
            //            \\"data\\":\\"510000,510600,510626\\",
            //            \\"fieldType\\":5,
            //            \\"labelName\\":\\"籍贯\\",
            //            \\"opName\\":\\"包含\\",
            //            \\"valueName\\":\\"xxx\\"
            //        }
            //    ],
            //    \\"Name\\":\\"或者\\"
            //};
            //var n = 
            //string t = \"{\\"groupOp\\":\\"OR\\",                \\"rules\\":[                    {                        \\"field\\":\\"NativePlace\\",                        \\"op\\":\\"cn\\",                        \\"data\\":[                            \\"510000\\",                            \\"510600\\",                            \\"510626\\"                        ],                        \\"fieldType\\":5,                        \\"labelName\\":\\"籍贯\\",                        \\"opName\\":\\"包含\\",                        \\"valueName\\":\\"xxx\\"                    }                ],                \\"Name\\":\\"或者\\"            }\";
            //string t = "{\"groupOp\":\"OR\",\"rules\":[{\"field\":\"NativePlace\",\"op\":\"cn\",\"data\":\"510000,510600,510626\",\"fieldType\":5,\"labelName\":\"籍贯\",\"opName\":\"包含\",\"valueName\":\"xxx\"}],\"Name\":\"或者\"}";
            //var filter = JsonConvert.DeserializeObject<Filter>(t);
            ////var fList = new List<Filter>();
            ////fList.Add(filter);
            //var nList = Trans.TransObj2(filter);
            //Console.WriteLine(nList);
            //Console.WriteLine();
            //fList.

            //Trans.TransObj(ref filter);
            //Console.WriteLine(JsonConvert.SerializeObject(filter));

            // var dic = new Dictionary<string, string>();
            // dic.Add("1","1234");
            // dic.Add("2", "1234");
            // dic.Add("3", "1234");
            // Console.WriteLine(dic.ToString());
            // Console.WriteLine(JsonConvert.SerializeObject(dic) );
            //
            // var t = JsonConvert.SerializeObject(dic);
            // Console.WriteLine(JsonConvert.DeserializeObject(t) );


            //DateTime dt1 = DateTime.Now.AddDays(10);
            //var days = DateTime.Now.Subtract(dt1).Days;
            //var days2 = dt1.Subtract(DateTime.Now).Days;

            //var list = new List<Student>() { new Student() {
            //name="1",StartDate = DateTime.Now.AddMonths(-2),status =0},new Student() {
            //name="2",StartDate = DateTime.Now.AddMonths(-1),status =0} };

            //var tlist = list.GroupBy(p => p.StartDate);
            //foreach (var item in tlist)
            //{
            //    Console.WriteLine(item);
            //}

            //var tlist = list.GroupBy(p => new { p.StartDate,p.status,p.name});
            //foreach (var item in tlist)
            //{
            //    //Console.WriteLine(item.Key.name);
            //    Console.WriteLine(item.ToList());
            //}

            //var t =new List<string>() {  "T1", "B2", "C4", "L1476" };

            ////Console.WriteLine(Regex.Replace(t, @"[^0-9]+", ""));
            //Console.WriteLine(JsonConvert.SerializeObject( GetArray(t)));

            //DataTable dt = new DataTable();
            //string str = "1+2*(5+3)+3-1";

            //Console.WriteLine(dt.Compute(str, "false").ToString());

            // NClass.MM;
            // TestLib
            // NClass
            // NClass.MM;

            //var info = new ExpressionFilter() { 
            //    OrgIds = new List<OrgInfo>() { 
            //        new OrgInfo(){
            //            OrgId=new Guid("86BD7940-A61F-4EBD-8A78-0D3234AF7E6D"),
            //            Name = "产科"
            //        },
            //    },
            //    IdentityInfo = new IdentityInfo() {
            //    IdentityCode = new Guid("676A26B8-CC5D-4818-AC40-AC8E00E54979"),
            //     Name = "护理"
            //    }
            //};
            //Console.WriteLine(JsonConvert.SerializeObject(info));
            //decimal c = Decimal.Parse("3.1265");
            //Console.WriteLine(string.Format("{0:N2}", c));


            GetPrograssCount();

            Console.ReadLine();
        }
        

        public static IEnumerable<string> GetArray(List<string> list) {
            var t = new List<int>() ;
            //var archiveList = existRecords.Select(p => p.archivesId);
            var n = list.Select(p => int.Parse( Regex.Replace(p, @"[^0-9]+", "")));
            var maxValue = n.Max();
            var nList = new List<string>();
            for (int i = 1; i < maxValue; i++)
            {
                if (!n.Contains(i)) { nList.Add($"{i}"); };
                if (nList.Count() >= 10) break;
            }
            if (nList.Count() < 10)
            {
                var nCount = nList.Count();
                for (int i = maxValue; i < maxValue+10- nCount; i++)
                {
                    nList.Add($"{i}");
                }
            }
            return nList;
        }
        /// <summary>
        /// 得到一个汉字的拼音第一个字母，如果是一个英文字母则直接返回大写字母
        /// </summary>
        /// <param name="CnChar">单个汉字</param>
        /// <returns>单个大写字母</returns>

        private static string GetCharSpellCode(string CnChar)
        {

            long iCnChar;

            byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);

            //如果是字母，则直接返回

            if (ZW.Length == 1)
            {

                return CnChar.ToUpper();

            }

            else
            {

                // get the array of byte from the single char

                int i1 = (short)(ZW[0]);

                int i2 = (short)(ZW[1]);

                iCnChar = i1 * 256 + i2;

            }

            // iCnChar match the constant

            if ((iCnChar >= 45217) && (iCnChar <= 45252))
            {

                return "A";

            }

            else if ((iCnChar >= 45253) && (iCnChar <= 45760))
            {

                return "B";

            }
            else if ((iCnChar >= 45761) && (iCnChar <= 46317))
            {

                return "C";

            }
            else if ((iCnChar >= 46318) && (iCnChar <= 46825))
            {

                return "D";

            }
            else if ((iCnChar >= 46826) && (iCnChar <= 47009))
            {

                return "E";

            }
            else if ((iCnChar >= 47010) && (iCnChar <= 47296))
            {

                return "F";

            }
            else if ((iCnChar >= 47297) && (iCnChar <= 47613))
            {

                return "G";

            }
            else if ((iCnChar >= 47614) && (iCnChar <= 48118))
            {

                return "H";

            }
            else if ((iCnChar >= 48119) && (iCnChar <= 49061))
            {

                return "J";

            }
            else if ((iCnChar >= 49062) && (iCnChar <= 49323))
            {

                return "K";

            }
            else if ((iCnChar >= 49324) && (iCnChar <= 49895))
            {

                return "L";

            }
            else if ((iCnChar >= 49896) && (iCnChar <= 50370))
            {

                return "M";

            }
            else if ((iCnChar >= 50371) && (iCnChar <= 50613))
            {

                return "N";

            }
            else if ((iCnChar >= 50614) && (iCnChar <= 50621))
            {

                return "O";

            }
            else if ((iCnChar >= 50622) && (iCnChar <= 50905))
            {

                return "P";

            }
            else if ((iCnChar >= 50906) && (iCnChar <= 51386))
            {

                return "Q";

            }
            else if ((iCnChar >= 51387) && (iCnChar <= 51445))
            {

                return "R";

            }
            else if ((iCnChar >= 51446) && (iCnChar <= 52217))
            {

                return "S";

            }
            else if ((iCnChar >= 52218) && (iCnChar <= 52697))
            {

                return "T";

            }
            else if ((iCnChar >= 52698) && (iCnChar <= 52979))
            {

                return "W";

            }
            else if ((iCnChar >= 52980) && (iCnChar <= 53640))
            {

                return "X";

            }
            else if ((iCnChar >= 53689) && (iCnChar <= 54480))
            {

                return "Y";

            }
            else if ((iCnChar >= 54481) && (iCnChar <= 55289))
            {

                return "Z";

            }
            else

                return ("?");

        }

        public static class Trans
        {
            //public static void TransObj(ref Filter filter)
            //{
            //    if (filter.rules != null && filter.rules.Count > 0)
            //    {
            //        for (int i = 0; i < filter.rules.Count; i++)
            //        {
            //            if (filter.rules[i].field.Equals("NativePlace"))
            //            {
            //                var data = filter.rules[i].data;
            //                if (data != null && data.ToString().Length > 0)
            //                {
            //                    filter.rules[i].data = data.ToString().Split(',');
            //                }
            //            }
            //        }
            //    }
            //    if (filter.groups != null && filter.groups.Count > 0)
            //    {
            //        for (int j = 0; j < filter.groups.Count; j++)
            //        {
            //            var filterJ = filter.groups[j];
            //            TransObj(ref filterJ);
            //            filter.groups[j] = filterJ;
            //        }
            //    }
            //}

            //public static List<FilterRules> TransObj2(Filter filter)
            //{
            //    var list = new List<FilterRules>();
            //    if (filter.rules != null && filter.rules.Count > 0)
            //    {
            //        list.AddRange(filter.rules as IEnumerable<FilterRules>);
            //    }
            //    if (filter.groups != null && filter.groups.Count > 0)
            //    {
            //        for (int j = 0; j < filter.groups.Count; j++)
            //        {
            //            var filterJ = filter.groups[j];
            //            list.AddRange(TransObj2(filterJ));
            //        }
            //    }
            //    return list;
            //}
        }

        public static void GetPrograssCount() {
            var contract = new StaffContract() {
                contractStatus = EIP.HRP.Models.Enums.ContractStatusEnum.已签订,
                createDate = DateTime.Now,
                id = Guid.NewGuid(),
                hasProbation = false,
                number = "111",
                probationStartDate = DateTime.Now,
            };

            Type t = contract.GetType();
            var noWriteCount = 0;
            var allNeedWirteCount = 0;
            foreach (PropertyInfo item in t.GetProperties())
            {
                var name = item.Name;
                var requireList = item.GetCustomAttributes(typeof(RequiredAttribute));
                if (requireList.Count() > 0) {
                    allNeedWirteCount++;
                    if (item.GetValue(contract, null) == null)
                    {
                        noWriteCount++;
                    }
                }
                

            }
            Console.WriteLine($"全部有：{allNeedWirteCount}个");
            Console.WriteLine($"未填有：{noWriteCount}个");
        }    

    }


}


